package com.lht.designPattern.state;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Eric
 * @version 1.0
 * @date 2019-10-12
 */
public class OrderStateContext implements OrderState {

    private static Map<Integer, OrderState> orderStates = new HashMap<>();

    static {
        // 这里初始化，可以通过 spring容器实现开闭
        orderStates.put(0, new WaitPayState());
        orderStates.put(1, new InitiatePayState());
    }
    @Override
    public boolean isChange(Order order, Integer state) {
        return orderStates.get(order.getOrderState()).isChange(order, state);
    }

    @Override
    public void change(Order order, Integer state) {
        orderStates.get(order.getOrderState()).change(order, state);
    }

}
